﻿package code {
	// class replicates a flipper
	public class Flipper extends GameObject {
		public var rotated:Boolean;
		private var mass:Number = 10;
		private var omega:Number;
		private var flipperType:String;
		// creates a flipper
		public function Flipper(shapeType:String, radius:Number, sides:Number, color:uint, thickness:Number, hollow:Boolean, angle:Number = 0, lineHeight:int = 0, flipperType:String = "") {
			super(shapeType, radius, sides, color, thickness, hollow, angle, lineHeight);
			rotated = false;
			omega = -.3
			this.flipperType = flipperType;
		}
		
		// rotates the flipper 
		public function rotateFlipper(angle:Number){
			if((flipperType == "left" && shape.angle > angle) || (flipperType == "right" && shape.angle < angle)){ // sets bounds for angle
				var oldLines = shape.linesArray;
				
				shape.graphics.clear();
				if(flipperType == "left")
					shape.angle += omega;
				else
					shape.angle -= omega;
				shape.rotateVertices();
				shape.renderVertices();
				

				shape.linesArray = createLinesArray();
				
			}
			rotated = true;
		}
		
		// rotaets it back
		public function rotateFlipperBack(angle:Number){
			if(((flipperType == "left" && shape.angle < angle) || flipperType == "right" && shape.angle > angle) && !rotated){
				
				shape.graphics.clear();
				if(flipperType == "left")
					shape.angle -= omega;
				else
					shape.angle += omega;
				shape.rotateVertices();
				shape.renderVertices();
				
				shape.linesArray = createLinesArray();
				
			}

		}
		
		// returns the current intertia of the bar
		public function getInertia(leverArmDisplacement:Number):Number{
			return ((2 /3) * mass * Math.pow(leverArmDisplacement, 2));
		}

	}
	
}
